#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :RSA算法加密.py
# @Time      :2024/4/12 15:09
# @Author    :Sherlock
import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5

text = "what's the weather like in summer"

with open("publick_key.pem", "rb") as f:
    public_key = RSA.import_key(f.read())


def encrypt_(public_key, text):
    # 创建算法对象
    cipher = PKCS1_v1_5.new(public_key)
    # 使用算法对象进行加密
    cipher_text = cipher.encrypt(text.encode())
    # 返回base64编码值
    return base64.b64encode(cipher_text).decode()


encrypted_text = encrypt_(public_key, text)
print(encrypted_text)
# j24qWVIELqbPTesfMaXO7aMJ3AoOQK6Qu+fWbNS219U3pJC7FhSbAxTppBd1YGVXSkU0PhqYOumu0mKpcd8q56XCQQTYsmUsqx5YPa1NA8Ns/axSH2QocHA2rKUqHwU++CS/yRIU14rKSFrhtpICMo6915M+yoWXmQFFp4FhOTo=
